//
//  XFMultisSelectView.m
//  WorkManager
//
//  Created by ukongm on 17/2/16.
//  Copyright © 2017年 ukongm. All rights reserved.
//

#import "XFMultisSelectView.h"

@implementation XFMultisSelectView
{
    NSMutableArray* _curIndexs; //当前选中的index，没有确认，再次show，就重置
    void (^_complateBlock)(NSArray*); //保存回调事件
}

- (BOOL)multis{
    return YES;
}

- (instancetype)init{
    self = [super init];
    
    if (self) {
        _curIndexs = [NSMutableArray new];
    }
    return self;
}

- (void)fixedAction{
    self.selectIndexs = [NSArray arrayWithArray:_curIndexs];
    if (_complateBlock) {
        _complateBlock(_curIndexs);
    }
    [self hide];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self fixedBtnChangeStyle];
    
    [_curIndexs addObject:@(indexPath.section)];
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self fixedBtnChangeStyle];
    
    [_curIndexs removeObject:@(indexPath.section)];
}

- (void)showInView:(UIView *)view fixedBlock:(void (^)(NSArray *))fixedBlock{
    
//    for (NSNumber* temp in self.selectIndexs) {
//        
//        NSInteger index = temp.integerValue;
//        
//        if (index < self.titles.count) {
//            [_curIndexs addObject:@(index)];
//            [self setSelectItem:index];
//        }
//    }
    
    [super showInView:view fixedBlock:nil];
    
    _complateBlock = fixedBlock;
}



@end
